package dhm.com.dhmshop.adapter.home;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.framework.module.commodity.activity.CommodityDetailsActivity;
import dhm.com.dhmshop.framework.module.home.activity.RecommendShopListActivity;
import dhm.com.dhmshop.framework.module.home.entity.ListHotGoodsEntity;
import dhm.com.dhmshop.framework.module.home.entity.RecommendShopListEntity;
import dhm.com.dhmshop.updata.activity.ShopdetailActivity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class RecommendShopListAdapter extends RecyclerView.Adapter<RecommendShopListAdapter.ViewHolder> {

    private List<RecommendShopListEntity.DataBean> shopList;
    private Context context;


    public RecommendShopListAdapter(Context context) {
        this.shopList = new ArrayList<>();
        this.context = context;
    }


    public void setShopList(List<RecommendShopListEntity.DataBean> shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.recommend_shop_list_item, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        viewHolder.image_recomshoplist.setImageURI(Constant.PATH+"/"+shopList.get(i).getImg());
        if (shopList.get(i).getGoods_list()!=null&&shopList.get(i).getGoods_list().size()>=1){
            viewHolder.recommendshoplist_ivone.setImageURI(Constant.PATH+"/"+shopList.get(i).getGoods_list().get(0).getGoods_images_thumb());
            viewHolder.recommendshoplist_ivone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(context, CommodityDetailsActivity.class);
                    intent.putExtra("gid",shopList.get(i).getGoods_list().get(0).getGoods_id());
                    intent.putExtra("shop_id",shopList.get(i).getShop_id());
                    context.startActivity(intent);
                }
            });
        }
        if (shopList.get(i).getGoods_list()!=null&&shopList.get(i).getGoods_list().size()>=2){
            viewHolder.recommendshoplist_ivtwo.setImageURI(Constant.PATH+"/"+shopList.get(i).getGoods_list().get(1).getGoods_images_thumb());
            viewHolder.recommendshoplist_ivtwo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(context, CommodityDetailsActivity.class);
                    intent.putExtra("gid",shopList.get(i).getGoods_list().get(1).getGoods_id());
                    intent.putExtra("shop_id",shopList.get(i).getShop_id());
                    context.startActivity(intent);
                }
            });
        }
        if (shopList.get(i).getGoods_list()!=null&&shopList.get(i).getGoods_list().size()>=3){
            viewHolder.recommendshoplist_ivthree.setImageURI(Constant.PATH+"/"+shopList.get(i).getGoods_list().get(2).getGoods_images_thumb());
            viewHolder.recommendshoplist_ivthree.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(context, CommodityDetailsActivity.class);
                    intent.putExtra("gid",shopList.get(i).getGoods_list().get(2).getGoods_id());
                    intent.putExtra("shop_id",shopList.get(i).getShop_id());
                    context.startActivity(intent);
                }
            });
        }

        viewHolder.title_recomshoplist.setText(shopList.get(i).getStore_name());
        viewHolder.desc_recomshoplist.setText(shopList.get(i).getStore_name()+"");
        viewHolder.jindian_recomshoplist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent=new Intent(context, ShopdetailActivity.class);
                intent.putExtra("shop_id",shopList.get(i).getShop_id()+"");
                context.startActivity(intent);
            }
        });

//        viewHolder.check.onTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,0,0,0));

    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView image_recomshoplist;
        public SimpleDraweeView recommendshoplist_ivone;
        public SimpleDraweeView recommendshoplist_ivtwo;
        public SimpleDraweeView recommendshoplist_ivthree;
        public TextView title_recomshoplist;
        public TextView desc_recomshoplist;
        public TextView jindian_recomshoplist;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            image_recomshoplist=itemView.findViewById(R.id.image_recomshoplist);
            title_recomshoplist=itemView.findViewById(R.id.title_recomshoplist);
            desc_recomshoplist=itemView.findViewById(R.id.desc_recomshoplist);
            jindian_recomshoplist=itemView.findViewById(R.id.jindian_recomshoplist);
            recommendshoplist_ivone=itemView.findViewById(R.id.recommendshoplist_ivone);
            recommendshoplist_ivtwo=itemView.findViewById(R.id.recommendshoplist_ivtwo);
            recommendshoplist_ivthree=itemView.findViewById(R.id.recommendshoplist_ivthree);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion, boolean checked);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion, int num);
    }

    private OnShopClick onshopClick;
    public void setaddClick(OnShopClick onClick) {
        this.onshopClick= onClick;
    }
    public interface OnShopClick{
        void item(int posttion);
    }



}

